<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .son {
      width: 100px;
      height: 100px;
      background-color: #000000;
      font-size: 25px;
      text-align: center;
      line-height: 100px;
      margin: 10px auto;
      -moz-user-select: none;
      -webkit-user-select: none;
      user-select: none;
      color: #171718;
      position: absolute;
    }
  </style>
</head>

<body>
  <div class="son">拖拽移动</div>
</body>
<script>
  /*
  1.当鼠标在box上按下时，功能开始（mousedown）
  2.鼠标移动，box跟随鼠标一起移动（mousemove）
  3.鼠标松开，功能结束，（mouseup）
  */
  var son = document.querySelector('.son')
  son.addEventListener('mousedown', function (e) {
    function move(e) {
      var x = e.pageX
      var y = e.pageY
      son.style.top = y - 10 + 'px'
      son.style.left = x - 10 + 'px'
    }
    document.addEventListener('mousemove', move)
    document.addEventListener('mouseup', function () {
      document.removeEventListener('mousemove', move)
    })
  })
</script>

</html>